import { User } from 'src/user/entities/user.entity';
import { Entity, PrimaryGeneratedColumn, ManyToOne, Unique } from 'typeorm';
import { Post } from './post.entity';

@Entity({ name: 'post_likes' })
@Unique(['user', 'post']) // 确保每个用户在同一篇帖子上只能点赞一次
export class PostLike {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => User, (user) => user.postLikes)
  user: User;

  @ManyToOne(() => Post, (post) => post.postLike, { onDelete: 'CASCADE' })
  post: Post;
}
